<template>
  <view class="user-profile-container">
    <!-- 顶部导航栏 -->
    <view class="navbar">
      <view class="nav-left">
        <button class="nav-btn" @tap="goBack">
          <text class="icon">←</text>
        </button>
      </view>
      <view class="nav-center">
        <text class="title">个人资料</text>
      </view>
      <view class="nav-right">
        <button class="nav-btn" @tap="saveProfile">
          <text class="save-text">保存</text>
        </button>
      </view>
    </view>

    <!-- 个人资料内容 -->
    <view class="profile-content">
      <!-- 头像区域 -->
      <view class="avatar-section">
        <image 
          class="avatar-image" 
          src="/static/VK_MDY_lightmode.png" 
          mode="aspectFit"
        />
      </view>

      <!-- 基本信息 -->
      <view class="info-section">
        <view class="info-item">
          <text class="label">用户名</text>
          <input 
            class="input" 
            v-model="userInfo.username" 
            placeholder="请输入用户名"
            maxlength="20"
          />
        </view>
        
        <view class="info-item">
          <text class="label">邮箱</text>
          <input 
            class="input" 
            v-model="userInfo.email" 
            placeholder="请输入邮箱"
            type="email"
          />
        </view>
        
        <view class="info-item">
          <text class="label">手机号</text>
          <input 
            class="input" 
            v-model="userInfo.phone" 
            placeholder="请输入手机号"
            type="number"
            maxlength="11"
          />
        </view>
        
        <view class="info-item">
          <text class="label">个性签名</text>
          <textarea 
            class="textarea" 
            v-model="userInfo.signature" 
            placeholder="请输入个性签名"
            maxlength="100"
            auto-height
          />
        </view>
      </view>



      <!-- 操作按钮 -->
      <view class="action-section">
        <button class="action-btn logout-btn" @tap="logout">退出登录</button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {
        username: '',
        email: '',
        phone: '',
        signature: ''
      },
      originalUserInfo: {}
    }
  },
  
  onLoad() {
    this.loadUserInfo()
  },
  
  methods: {
    // 加载用户信息
    loadUserInfo() {
      const userInfo = uni.getStorageSync('userInfo') || {}
      this.userInfo = {
          username: userInfo.username || '用户',
          email: userInfo.email || '',
          phone: userInfo.phone || '',
          signature: userInfo.signature || ''
        }
      this.originalUserInfo = JSON.parse(JSON.stringify(this.userInfo))
    },
    
    // 保存用户信息
    async saveProfile() {
      try {
        // 模拟保存到服务器
        uni.setStorageSync('userInfo', this.userInfo)
        uni.showToast({
          title: '保存成功',
          icon: 'success'
        })
        this.originalUserInfo = JSON.parse(JSON.stringify(this.userInfo))
      } catch (error) {
        uni.showToast({
          title: '保存失败',
          icon: 'none'
        })
      }
    },
    
    // 返回
    goBack() {
      uni.navigateBack()
    },
    
    // 退出登录
    logout() {
      uni.showModal({
        title: '提示',
        content: '确定要退出登录吗？',
        success: (res) => {
          if (res.confirm) {
            uni.removeStorageSync('token')
            uni.removeStorageSync('userInfo')
            uni.reLaunch({
              url: '/pages/login/index'
            })
          }
        }
      })
    },
    

  }
}
</script>

<style scoped>
.user-profile-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  background: #f5f5f5;
  overflow: hidden;
}

/* 导航栏样式 */
.navbar {
  display: flex;
  align-items: center;
  padding: 20rpx 30rpx;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.nav-left {
  flex: 1;
}

.nav-center {
  flex: 2;
  text-align: center;
}

.nav-right {
  flex: 1;
  text-align: right;
}

.nav-btn {
  background: transparent;
  border: none;
  color: white;
  font-size: 32rpx;
  padding: 10rpx 20rpx;
}

.title {
  font-size: 36rpx;
  font-weight: bold;
}

.save-text {
  font-size: 28rpx;
}

/* 内容区域 */
.profile-content {
  flex: 1;
  padding: 20rpx;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 头像区域 */
.avatar-section {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40rpx 0;
  background: white;
  margin-bottom: 20rpx;
  border-radius: 20rpx;
  flex-shrink: 0;
}

.avatar-image {
  width: 100rpx;
  height: 100rpx;
  border-radius: 50%;
  border: 3rpx solid #667eea;
}

/* 信息区域 */
.info-section,
.account-section {
  background: white;
  margin-bottom: 20rpx;
  border-radius: 20rpx;
  padding: 30rpx;
  flex-shrink: 0;
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  margin-bottom: 30rpx;
  color: #333;
}

.info-item {
  display: flex;
  align-items: center;
  padding: 25rpx 0;
  border-bottom: 1rpx solid #eee;
}

.info-item:last-child {
  border-bottom: none;
}

.label {
  width: 150rpx;
  font-size: 28rpx;
  color: #333;
  font-weight: bold;
}

.input,
.textarea {
  flex: 1;
  font-size: 28rpx;
  color: #666;
  border: none;
  outline: none;
  background: transparent;
}

.textarea {
  min-height: 60rpx;
  padding: 10rpx 0;
}

.value {
  flex: 1;
  font-size: 28rpx;
  color: #666;
}

/* 操作按钮区域 */
.action-section {
  padding: 20rpx;
  margin-top: auto;
  flex-shrink: 0;
}

.action-btn {
  width: 100%;
  height: 80rpx;
  background: #ff6b6b;
  color: white;
  border: none;
  border-radius: 40rpx;
  font-size: 28rpx;
}

/* 响应式布局 */
@media screen and (max-width: 768px) {
  .user-profile-container {
    width: 100vw;
    height: 100vh;
  }
  
  .profile-content {
    padding: 15rpx;
  }
  
  .info-section,
  .account-section {
    margin-bottom: 15rpx;
    padding: 25rpx;
  }
  
  .avatar-section {
    padding: 30rpx 0;
  }
  
  .avatar-image {
    width: 90rpx;
    height: 90rpx;
  }
}

@media screen and (max-width: 480px) {
  .user-profile-container {
    width: 100vw;
    height: 100vh;
  }
  
  .profile-content {
    padding: 10rpx;
  }
  
  .info-section,
  .account-section {
    margin-bottom: 10rpx;
    padding: 20rpx;
  }
  
  .avatar-section {
    padding: 25rpx 0;
  }
  
  .avatar-image {
    width: 80rpx;
    height: 80rpx;
  }
  
  .info-item {
    padding: 20rpx 0;
  }
  
  .label {
    width: 120rpx;
    font-size: 26rpx;
  }
  
  .input,
  .textarea,
  .value {
    font-size: 26rpx;
  }
}
</style>